using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Shop_Manage_Shop_MyVIPUser : Member, IRequiresSessionState
{
	private int ShopID;
	protected ScriptManager ScriptManager1;
	protected TextBox TxtShopName;
	protected TextBox TxtNickName;
	protected Button QuickSearchButton;
	protected DropDownList DropShopLevel;
	protected GridView GridView1;
	protected UpdatePanel UpdatePanel1;
	protected Button Button1;
	protected Button Button3;
	protected Button Button2;
	protected DropDownList DropDownList1;
	protected Button Button4;
	protected Button Button5;
	protected TextBox TxtMoney;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected RangeValidator RangeValidator1;
	protected ObjectDataSource ObjectDataSource1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.ShopID = base.user.ShopID;
		if (this.ShopID <= 0)
		{
			this.WriteErrMsg("友情提示", Language.GetMemberMsg("Common/NoShop", new string[0]), "../Member/Shop_OpenShop.aspx");
		}
	}
	protected void Button1_Click(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
			checkBox.Checked = true;
		}
	}
	protected void Button3_Click(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
			checkBox.Checked = false;
		}
	}
	protected void Button2_Click(object sender, EventArgs e)
	{
		string text = "";
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
			if (checkBox.Checked)
			{
				text = text + gridViewRow.Cells[1].Text + ",";
			}
		}
		if (text.Length > 1)
		{
			text = text.Remove(text.Length - 1);
			Shop_VIP shop_VIP = new Shop_VIP();
			shop_VIP.DeleteVIPS(text);
			this.ObjectDataSource1.Update();
		}
	}
	protected void Button4_Click(object sender, EventArgs e)
	{
		string text = "";
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
			if (checkBox.Checked)
			{
				text = text + gridViewRow.Cells[1].Text + ",";
			}
		}
		if (text.Length > 1)
		{
			text = text.Remove(text.Length - 1);
			Shop_VIP shop_VIP = new Shop_VIP();
			shop_VIP.UpdateLevel(text, this.DropDownList1.SelectedValue.Trim());
			this.ObjectDataSource1.Update();
		}
	}
	protected void Button5_Click(object sender, EventArgs e)
	{
		int num = 0;
		Shop_VIP shop_VIP = new Shop_VIP();
		UserBll userBll = new UserBll();
		int num2 = 0;
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
			if (checkBox.Checked)
			{
				num2++;
			}
		}
		num = int.Parse(this.Session["Howave_UserID"].ToString());
		decimal d = decimal.Parse(userBll.GetUserByUserID(num).Rows[0]["Balance"].ToString());
		if (decimal.Parse(this.TxtMoney.Text) * num2 > d)
		{
			this.Button5.Text = "你的余额不足，请及时冲值";
			this.Button5.Width = 200;
		}
		else
		{
			foreach (GridViewRow gridViewRow in this.GridView1.Rows)
			{
				CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
				if (checkBox.Checked)
				{
					int vIPID = int.Parse(gridViewRow.Cells[1].Text);
					DataTable singleVIPCard = shop_VIP.GetSingleVIPCard(vIPID);
					if (singleVIPCard.Rows.Count >= 1)
					{
						int num3 = int.Parse(singleVIPCard.Rows[0]["UserID"].ToString());
						Shop_BankrollItem shop_BankrollItem = new Shop_BankrollItem();
						shop_BankrollItem.AddBankrollItem(num3, num, decimal.Parse(this.TxtMoney.Text), 3, 0, 0, 0, 1, -1, 0, "管理会员时，给客户送现金券", "卖家已经确认");
						this.conn.BeginTransaction();
						try
						{
							this.conn.ExecuteTransaction(string.Concat(new object[]
							{
								"Update [HL_User] Set Balance=Balance+",
								decimal.Parse(this.TxtMoney.Text),
								" Where ID=",
								num3
							}));
							this.conn.ExecuteTransaction(string.Concat(new object[]
							{
								"Update [HL_User] Set Balance=Balance-",
								decimal.Parse(this.TxtMoney.Text),
								" Where ID=",
								num
							}));
						}
						catch
						{
							this.conn.Rollback();
							return;
						}
						this.conn.Commit();
					}
				}
			}
			this.Button5.Text = "恭喜你，操作完成";
		}
	}
}
